home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / MacHacksBug / Python 1.5.2c1 / Mac / Lib / test / tlist.py < prev    next >
Encoding:
Python Source  |  2000-06-23  |  2.2 KB  |  93 lines

  1. # Test List module.
  2. # Draw a window with all the files in the current folder.
  3. # double-clicking will change folder.
  4. #
  5. # This test expects Win, Evt and FrameWork (and anything used by those)
  6. # to work.
  7. #
  8. # Actually, it is more a test of FrameWork by now....
  9.  
  10. from FrameWork import *
  11. import Win
  12. import Qd
  13. import List
  14. import Lists
  15. import os
  16.  
  17. class ListWindow(Window):
  18.     def open(self, name, where):
  19.         self.where = where
  20.         r = (40, 40, 400, 300)
  21.         w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
  22.         r2 = (0, 0, 345, 245)
  23.         Qd.SetPort(w)
  24.         self.wid = w
  25.         self.list = List.LNew(r2, (0, 0, 1, 1), (0,0), 0, w, 0, 1, 1, 1)
  26.         self.list.selFlags = Lists.lOnlyOne
  27.         self.filllist()
  28.         w.DrawGrowIcon()
  29.         self.do_postopen()
  30.         
  31.     def do_activate(self, onoff, evt):
  32.         self.list.LActivate(onoff)
  33.  
  34.     def do_update(self, *args):
  35.         self.list.LUpdate(self.wid.GetWindowPort().visRgn)
  36.         
  37.     def do_contentclick(self, local, modifiers, evt):
  38.         dclick = self.list.LClick(local, modifiers)
  39.         if dclick:
  40.             h, v = self.list.LLastClick()
  41.             file = self.list.LGetCell(1000, (h, v))
  42.             self.where = os.path.join(self.where, file)
  43.             self.filllist()
  44.  
  45.     def filllist(self):
  46.         """Fill the list with the contents of the current directory"""
  47.         l = self.list
  48.         l.LSetDrawingMode(0)
  49.         l.LDelRow(0, 0)
  50.         contents = os.listdir(self.where)
  51.         l.LAddRow(len(contents), 0)
  52.         for i in range(len(contents)):
  53.             l.LSetCell(contents[i], (0, i))
  54.         l.LSetDrawingMode(1)
  55.         l.LUpdate(self.wid.GetWindowPort().visRgn)
  56.  
  57.  
  58. class TestList(Application):
  59.     def __init__(self):
  60.         Application.__init__(self)
  61.         self.num = 0
  62.         self.listoflists = []
  63.         
  64.     def makeusermenus(self):
  65.         self.filemenu = m = Menu(self.menubar, "File")
  66.         self.newitem = MenuItem(m, "New window...", "O", self.open)
  67.         self.quititem = MenuItem(m, "Quit", "Q", self.quit)
  68.     
  69.     def open(self, *args):
  70.         import macfs
  71.         fss, ok = macfs.GetDirectory()
  72.         if not ok:
  73.             return
  74.         w = ListWindow(self)
  75.         w.open('Window %d'%self.num, fss.as_pathname())
  76.         self.num = self.num + 1
  77.         self.listoflists.append(w)
  78.         
  79.     def quit(self, *args):
  80.         raise self
  81.  
  82.     def do_about(self, id, item, window, event):
  83.         EasyDialogs.Message("""Test the List Manager interface.
  84.         Simple inward-only folder browser""")
  85.  
  86. def main():
  87.     App = TestList()
  88.     App.mainloop()
  89.     
  90. if __name__ == '__main__':
  91.     main()
  92.     
  93.